const initWebsocket = require("../../config/websocket.config");
/**
 * 通用接口，由操作集触发的接口和通过操作集调用3d场景的事件都可以通过该接口实现
 * @param {Obeject} data 传递的数据.
 * @param {string} toguys 传向何处(thingjs:3d场景端，web:大屏端).
 */
let timer = new Map();
timer.set('moniFire', null);
const commonController = {
  commonApi: (req, res) => {
    try {
      const { data, toguys, type, eventName } = req.body;
      if (!toguys) {
        res.send({
          code: 502,
          message: "请确定要通信的用户",
        });
        return;
      }
      let info = {
        eventName: eventName,
        toguys: toguys,
        data,
        type: type,
      };

      let result = initWebsocket.callPhone(info);
      if (result) {
        res.send({
          code: 200,
          message: "success",
        });
      } else {
        res.send({
          code: 500,
          message: "客户端未连接",
        });
      }
    } catch (error) {
      res.send({
        code: 501,
        message: error,
      });
    }
  },
  to2F: (req, res) => {
    try {
      const { data, toguys, type, eventName } = req.body;
      if (!toguys) {
        res.send({
          code: 502,
          message: "请确定要通信的用户",
        });
        return;
      }
      let info = {
        eventName: eventName,
        toguys: toguys,
        data,
        type: type,
      };

      let result = initWebsocket.callPhone(info);
      if (result) {
        res.send({
          code: 200,
          message: "success",
        });
      } else {
        res.send({
          code: 500,
          message: "客户端未连接",
        });
      }
    } catch (error) {
      res.send({
        code: 501,
        message: error,
      });
    }
  },

};
module.exports = commonController;
